package com.softeem.score.manager.controller.admin;


import com.github.pagehelper.PageInfo;
import com.softeem.score.common.log.annotation.Log;
import com.softeem.score.common.log.enums.OperatorType;
import com.softeem.score.manager.service.GradeService;
import com.softeem.score.model.dto.gradeDto.AdminScoreQueryDTO;
import com.softeem.score.model.dto.gradeDto.StudentScoreQueryDTO;
import com.softeem.score.model.vo.common.Result;
import com.softeem.score.model.vo.common.ResultCodeEnum;
import com.softeem.score.model.vo.educational.GradeVo;
import com.softeem.score.model.vo.educational.StudentScoreVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zhu
 * @since 2024-02-14
 */
@Tag(name = "成绩管理")
@RestController
@RequestMapping("/admin/educational/grade")
public class GradeController {

    @Autowired
    private GradeService gradeService;

    @Operation(summary = "分页查询成绩列表")
    @GetMapping(value = "/findByPage/{pageNum}/{pageSize}")
    public Result<PageInfo<GradeVo>> findByPage(AdminScoreQueryDTO adminScoreQueryDTO,
                                                @PathVariable(value = "pageNum") Integer pageNum,
                                                @PathVariable(value = "pageSize") Integer pageSize) {
        PageInfo<GradeVo> pageInfo = gradeService.findByPage(adminScoreQueryDTO, pageNum, pageSize);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }

    @Log(title = "查询个人成绩列表", businessType = 0, operatorType = OperatorType.STUDENT)
    @Operation(summary = "分页查询个人成绩列表")
    @GetMapping(value = "/findOwnerScoreListByPage/{pageNum}/{pageSize}")
    public Result<PageInfo<GradeVo>> findOwnerScoreListByPage(StudentScoreQueryDTO studentScoreQueryDTO,
                                                              @PathVariable(value = "pageNum") Integer pageNum,
                                                              @PathVariable(value = "pageSize") Integer pageSize) {
        PageInfo<StudentScoreVo> pageInfo = gradeService.findByPageByStudentNumber(studentScoreQueryDTO, pageNum, pageSize);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }


    @Operation(summary = "统计分析")
    @GetMapping(value = "/getCharData/{courseId}")
    public Result<Map<String, Object>> getCharData(@PathVariable(value = "courseId") Long courseId) {
        Map<String, Object> charDate = gradeService.findAllGradeByCourseId(courseId);
        System.out.println("charDate = " + charDate);
        return Result.build(charDate, ResultCodeEnum.SUCCESS);
    }

}

